
package org.demoiselle.sample.view;

import javax.inject.Inject;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.template.AbstractEditPageBean;
import br.gov.frameworkdemoiselle.transaction.Transactional;
import org.demoiselle.sample.business.*;
import org.demoiselle.sample.domain.*;
import javax.faces.model.*;
import org.primefaces.event.TransferEvent;
import org.primefaces.model.DualListModel;
import java.util.*;

// To remove unused imports press: Ctrl+Shift+o

@ViewController
@PreviousView("./solicitante_list.jsf")
public class SolicitanteEditMB extends AbstractEditPageBean<Solicitante, Long> {

	private static final long serialVersionUID = 1L;

	@Inject
	private SolicitanteBC solicitanteBC;
	

	private DataModel<Paciente> pacienteList;
	
	public void addPaciente() {
		this.getBean().getPacientes().add(new Paciente());
	}
	public void deletePaciente() {
	   this.getBean().getPacientes().remove(getPacienteList().getRowData());
	}
	public DataModel<Paciente> getPacienteList() {
	   if (pacienteList == null) {
		   pacienteList = new ListDataModel<Paciente>(this.getBean().getPacientes());
	   }
	   return pacienteList;
	} 
	
	@Override
	@Transactional
	public String delete() {
		this.solicitanteBC.delete(getId());
		return getPreviousView();
	}
	
	@Override
	@Transactional
	public String insert() {
		this.solicitanteBC.insert(this.getBean());
		return getPreviousView();
	}
	
	@Override
	@Transactional
	public String update() {
		this.solicitanteBC.update(this.getBean());
		return getPreviousView();
	}
	
	@Override
	protected Solicitante handleLoad(Long id) {
		return this.solicitanteBC.load(id);
	}	
}